from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout

class Bin2cConan(ConanFile):
    name = "bin2c"
    version = "1.0.0"

    # Optional metadata
    license = "BSD-2-Clause"
    author = "gwilymk 10km"
    url = "https://gitee.com/l0km/bin2c"
    description = "A simple utility for converting a binary file to a c application which can then be included within an application."
    topics = ("bin")

    # Binary configuration
    settings = "os", "build_type", "arch"
    options = {"use_bz2": [True, False]}
    default_options = {"use_bz2" : False}
    generators = "CMakeDeps"
    # Sources are located in the same place as this recipe, copy them to the recipe
    exports_sources = "CMakeLists.txt", "src/*"

    package_type = "application"

    def requirements(self):
        if self.options.use_bz2 :
            self.requires("bzip2/1.0.8")

    def generate(self):
        tc = CMakeToolchain(self)
        tc.variables["USE_BZ2"] = self.options.use_bz2
        tc.generate()

    def build(self):
        cmake = CMake(self)
        cmake.configure()
        cmake.build()

    def package_id(self):
        del self.info.settings.build_type

    def package(self):
        cmake = CMake(self)
        cmake.install()

